﻿package mortal.game.view.common.tooltip.tooltips
{
    import Message.DB.Tables.*;
    import __AS3__.vec.*;
    import com.mui.controls.*;
    import com.mui.display.*;
    import com.mui.utils.*;
    import extend.language.*;
    import flash.display.*;
    import flash.text.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.common.text.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.utils.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.item.*;
    import mortal.game.view.common.tooltip.*;
    import mortal.game.view.common.tooltip.tooltips.base.*;
    import mortal.game.view.common.util.*;
    import mortal.game.view.shopMall.view.*;
    import mortal.game.view.skill.*;

    public class ToolTipDefenseEquip extends ToolTipScaleBg implements IToolTipBaseItemComparable
    {
        private var _txtName:GTextFiled;
        private var _icon:ShopSellItem;
        private var _bmpEquiped:Bitmap;
        private var _lockIcon:GBitmap;
        private var _txtBind:GTextFiled;
        private var _txtFight:GTextFiled;
        private var _sellPrice:GTextFiled;
        private var _txtSuitType:GTextFiled;
        private var _txtBasic:GTextFiled;
        private var _txtBasicLeft:AutoLayoutTextContainer;
        private var _lineBasic:ScaleBitmap;
        private var _activeSkillContianer:Sprite;
        private var _txtActiveSkill:GTextFiled;
        private var _txtActiveSkillDesc:GTextFiled;
        private var _lineAcitveSkill:ScaleBitmap;
        private var _unActiveSKillContianer:Sprite;
        private var _txtUnActiveSkill:GTextFiled;
        private var _txtUnActiveSkillDesc:GTextFiled;
        private var _lineUnactiveSkill:ScaleBitmap;
        private var _composeNeedContianer:Sprite;
        private var _txtComposeNeed:GTextFiled;
        private var _txtComposeNeedLeft:AutoLayoutTextContainer;
        private var _txtComposeNeedRight:AutoLayoutTextContainer;
        private var _lineComposeNeed:ScaleBitmap;
        private var _composeContianer:Sprite;
        private var _txtCompose:GTextFiled;
        private var _txtComposeLeft:AutoLayoutTextContainer;
        private var _txtComposeRight:AutoLayoutTextContainer;
        private var _data:ItemData;
        private var _info:ItemEquipInfo;
        private var _curY:int;

        public function ToolTipDefenseEquip()
        {
            this.createChildren();
            paddingBottom = 8;
            paddingLeft = 12;
            paddingRight = 8;
            paddingTop = 8;
            return;
        }// end function

        override public function set data(param1) : void
        {
            this._data = param1 as ItemData;
            if (this._data == null)
            {
                return;
            }
            this._info = this._data.itemInfo as ItemEquipInfo;
            setBg(ToolTipUtil.getBgNameByColor(this._info.color));
            this.updateTopPart();
            this.updateBasicAttr();
            this.updateSkill();
            this.updateLayout();
            _scaleBg.setSize(288, paddingTop + paddingBottom + this._curY + 10);
            this.updateName();
            super.data = this._data;
            return;
        }// end function

        public function setEquipedData(param1:Object) : void
        {
            return;
        }// end function

        private function updateTopPart() : void
        {
            var _loc_2:TDefenseCopyShopSell = null;
            var _loc_1:* = ItemsUtil.isBind(this._data);
            this._icon.itemData = this._data;
            this._icon.isBind = _loc_1;
            this._lockIcon.visible = _loc_1;
            if (_loc_1)
            {
                this._txtBind.textColor = GlobalStyle.colorHongUint;
                this._txtBind.text = Language.getString(20206);
                this._txtBind.x = 100;
            }
            else
            {
                this._txtBind.textColor = GlobalStyle.colorLvUint;
                this._txtBind.text = Language.getString(20205);
                this._txtBind.x = 79;
            }
            if (this._data.extInfo != null)
            {
                this._txtFight.text = Language.getString(30221) + "：" + EquipmentUtil.getEquipCombat(this._data);
            }
            else
            {
                this._txtFight.text = Language.getString(30221) + EquipmentUtil.getEquipBaseCombat(this._data);
            }
            if (ItemsUtil.isDefenseEquip(this._data))
            {
                _loc_2 = DefenseCopyShopConfig.instance.getItem(1, this._data.itemCode);
                if (_loc_2 == null)
                {
                    _loc_2 = DefenseCopyShopConfig.instance.getItem(0, this._data.itemCode);
                }
                if (_loc_2)
                {
                    this._sellPrice.htmlText = Language.getStringByParam(30259, Math.floor(_loc_2.buyValue / 2));
                }
            }
            else
            {
                this._sellPrice.htmlText = "";
            }
            return;
        }// end function

        private function updateBasicAttr() : void
        {
            var _loc_4:int = 0;
            var _loc_5:AttributeData = null;
            var _loc_1:* = AttributeUtil.getEquipmentBasicAttrs(this._data.itemInfo as ItemEquipInfo, this._data.addPercent);
            var _loc_2:* = this._txtBasicLeft.numChildren;
            var _loc_3:* = _loc_1.length - _loc_2;
            if (_loc_3 > 0)
            {
                _loc_4 = 0;
                while (_loc_4 < _loc_3)
                {
                    
                    this._txtBasicLeft.addNewText(120, "", 12, GlobalStyle.colorLvUint);
                    _loc_4++;
                }
            }
            else if (_loc_3 < 0)
            {
                this._txtBasicLeft.split(_loc_1.length);
            }
            _loc_4 = 0;
            while (_loc_4 < _loc_1.length)
            {
                
                _loc_5 = _loc_1[_loc_4];
                this._txtBasicLeft.setText(_loc_4, _loc_5.name + " : " + _loc_5.value);
                _loc_4++;
            }
            return;
        }// end function

        private function updateSkill() : void
        {
            var _loc_4:int = 0;
            var _loc_5:TSkill = null;
            var _loc_1:Array = [];
            if (this._data.itemInfo.skill != null)
            {
                _loc_1 = this._data.itemInfo.skill.split("#");
            }
            var _loc_2:Array = [];
            var _loc_3:Array = [];
            var _loc_6:* = new SkillInfo();
            var _loc_7:int = 0;
            while (_loc_7 < _loc_1.length)
            {
                
                _loc_4 = _loc_1[_loc_7];
                if (SkillUtil.isBeidongSkill(_loc_4))
                {
                    _loc_3.push(_loc_4);
                }
                else
                {
                    _loc_2.push(_loc_4);
                }
                _loc_7++;
            }
            if (_loc_2.length == 0)
            {
                DisplayUtil.removeMe(this._activeSkillContianer);
            }
            else
            {
                _contentContainer2D.addChild(this._activeSkillContianer);
                _loc_7 = 0;
                while (_loc_7 < _loc_2.length)
                {
                    
                    _loc_4 = _loc_2[_loc_7];
                    _loc_5 = SkillConfig.instance.getInfoById(_loc_4);
                    _loc_6.tSkill = _loc_5;
                    this._txtActiveSkillDesc.height = 120;
                    this._txtActiveSkillDesc.htmlText = SkillUtil.getSkillName(_loc_6) + " " + SkillUtil.getSkillDesc(_loc_4);
                    _loc_7++;
                }
            }
            if (_loc_3.length == 0)
            {
                DisplayUtil.removeMe(this._unActiveSKillContianer);
            }
            else
            {
                _contentContainer2D.addChild(this._unActiveSKillContianer);
                _loc_7 = 0;
                while (_loc_7 < _loc_3.length)
                {
                    
                    _loc_4 = _loc_3[_loc_7];
                    _loc_5 = SkillConfig.instance.getInfoById(_loc_4);
                    _loc_6.tSkill = _loc_5;
                    this._txtUnActiveSkillDesc.height = 120;
                    this._txtUnActiveSkillDesc.htmlText = SkillUtil.getSkillName(_loc_6) + " " + SkillUtil.getSkillDesc(_loc_4);
                    _loc_7++;
                }
            }
            return;
        }// end function

        private function updateComposeNeed() : void
        {
            var _loc_1:int = 0;
            var _loc_2:String = "";
            var _loc_3:* = DefenseCopyComposeConfig.instance.getConfigByItemCode(this._data.itemCode);
            if (_loc_3 == null)
            {
                DisplayUtil.removeAndDisposeAllGUIComponent(this._composeNeedContianer);
                return;
            }
            _contentContainer2D.addChild(this._composeNeedContianer);
            var _loc_4:Array = [];
            if (_loc_3.material1 != 0)
            {
                _loc_4.push(_loc_3.material1);
            }
            if (_loc_3.material2 != 0)
            {
                _loc_4.push(_loc_3.material2);
            }
            if (_loc_3.material3 != 0)
            {
                _loc_4.push(_loc_3.material3);
            }
            if (_loc_3.material4 != 0)
            {
                _loc_4.push(_loc_3.material4);
            }
            var _loc_5:* = this._txtComposeNeedLeft.numChildren;
            var _loc_6:* = _loc_4.length - _loc_5;
            if (_loc_6 > 0)
            {
                _loc_1 = 0;
                while (_loc_1 < _loc_6)
                {
                    
                    this._txtComposeNeedLeft.addNewText(120);
                    _loc_1++;
                }
            }
            else if (_loc_6 < 0)
            {
                this._txtComposeNeedLeft.split(_loc_4.length);
            }
            _loc_1 = 0;
            while (_loc_1 < _loc_4.length)
            {
                
                _loc_2 = ItemsUtil.getItemName(new ItemData(_loc_4[_loc_1]));
                this._txtComposeNeedLeft.setText(_loc_1, _loc_2, true);
                _loc_1++;
            }
            return;
        }// end function

        private function updateCanCompase() : void
        {
            var _loc_1:int = 0;
            var _loc_2:String = "";
            var _loc_3:* = DefenseCopyComposeConfig.instance.findIncludItemCodeConfigArr(this._data.itemCode);
            if (_loc_3.length <= 0)
            {
                DisplayUtil.removeMe(this._composeContianer);
                return;
            }
            _contentContainer2D.addChild(this._composeContianer);
            var _loc_4:* = this._txtComposeLeft.numChildren;
            var _loc_5:* = _loc_3.length - _loc_4;
            if (_loc_5 > 0)
            {
                _loc_1 = 0;
                while (_loc_1 < _loc_5)
                {
                    
                    this._txtComposeLeft.addNewText(120);
                    _loc_1++;
                }
            }
            else if (_loc_5 < 0)
            {
                this._txtComposeLeft.split(_loc_3.length);
            }
            _loc_1 = 0;
            while (_loc_1 < _loc_3.length)
            {
                
                _loc_2 = ItemsUtil.getItemName(new ItemData(_loc_3[_loc_1]));
                this._txtComposeLeft.setText(_loc_1, _loc_2, true);
                _loc_1++;
            }
            return;
        }// end function

        private function createChildren() : void
        {
            var _loc_1:* = GlobalStyle.textFormatPutong;
            _loc_1.align = TextFormatAlign.CENTER;
            _loc_1.size = 14;
            _loc_1.bold = true;
            this._txtName = UIFactory.gTextField("", -6, 0, 220, 25, this, _loc_1);
            this._icon = UICompomentPool.getUICompoment(ShopSellItem);
            this._icon.x = 0;
            this._icon.y = 26;
            this._icon.setItemStyle(ItemStyleConst.Big, ImagesConst.ShopItemBg, 6, 6);
            this._icon.createDisposedChildren();
            this.addChild(this._icon);
            this._icon.isShowLock = false;
            _loc_1 = GlobalStyle.embedNumberTf;
            _loc_1.color = GlobalStyle.colorHuangUint;
            _loc_1.align = TextFormatAlign.RIGHT;
            this._lockIcon = UIFactory.bitmap(ImagesConst.LockIcon, 81, 34, contentContainer2D);
            this._txtBind = UIFactory.gTextField("", 100, 30, 100, 20, contentContainer2D);
            this._sellPrice = UIFactory.gTextField("", 79, 60, 180, 20, contentContainer2D);
            this._txtFight = UIFactory.gTextField("", 158, 30, 120, 20, contentContainer2D);
            this._txtFight.textColor = 15911263;
            this._txtSuitType = UIFactory.gTextField("", 79, 52, 100, 20, contentContainer2D);
            this._txtBasic = UIFactory.gTextField(Language.getString(20210), 0, 114, 100, 20, contentContainer2D);
            this._txtBasic.textColor = GlobalStyle.colorChenUint;
            this._txtBasicLeft = new AutoLayoutTextContainer();
            this._txtBasicLeft.x = this._txtBasic.x;
            this._txtBasicLeft.y = this._txtBasic.y + 22;
            this._txtBasicLeft.verticalGap = -7;
            this.addChild(this._txtBasicLeft);
            this._lineBasic = UIFactory.bg(0, this._txtBasicLeft.y + this._txtBasicLeft.height, 256, 2, contentContainer2D, ImagesConst.SplitLine);
            this._activeSkillContianer = UIFactory.sprite(0, 194, contentContainer2D);
            this._txtActiveSkill = UIFactory.gTextField(Language.getString(20767), 0, 0, 100, 20, this._activeSkillContianer);
            this._txtActiveSkill.textColor = GlobalStyle.colorChenUint;
            _loc_1 = GlobalStyle.textFormatBai;
            this._txtActiveSkillDesc = UIFactory.gTextField("dsfadf", this._txtActiveSkill.x, this._txtActiveSkill.y + 25, 255, 60, this._activeSkillContianer, _loc_1, true);
            this._txtActiveSkillDesc.wordWrap = true;
            this._txtActiveSkillDesc.multiline = true;
            this._lineAcitveSkill = UIFactory.bg(0, this._txtActiveSkillDesc.y + 70, 256, 2, this._activeSkillContianer, ImagesConst.SplitLine);
            this._unActiveSKillContianer = UIFactory.sprite(0, 194, contentContainer2D);
            this._txtUnActiveSkill = UIFactory.gTextField(Language.getString(20768), 0, 0, 100, 20, this._unActiveSKillContianer);
            this._txtUnActiveSkill.textColor = GlobalStyle.colorChenUint;
            this._txtUnActiveSkillDesc = UIFactory.gTextField("dsfadf", this._txtUnActiveSkill.x, this._txtUnActiveSkill.y + 25, 255, 60, this._unActiveSKillContianer, _loc_1, true);
            this._txtUnActiveSkillDesc.wordWrap = true;
            this._txtUnActiveSkillDesc.multiline = true;
            this._lineUnactiveSkill = UIFactory.bg(0, this._txtUnActiveSkillDesc.y + 75, 256, 2, this._unActiveSKillContianer, ImagesConst.SplitLine);
            this._composeNeedContianer = UIFactory.sprite(0, 194);
            this._txtComposeNeed = UIFactory.gTextField(Language.getString(20769), 0, 0, 100, 20, this._composeNeedContianer);
            this._txtComposeNeed.textColor = GlobalStyle.colorChenUint;
            this._txtComposeNeedLeft = new AutoLayoutTextContainer();
            this._txtComposeNeedLeft.x = this._txtComposeNeed.x;
            this._txtComposeNeedLeft.y = this._txtComposeNeed.y + 25;
            this._txtComposeNeedLeft.verticalGap = -7;
            this._composeNeedContianer.addChild(this._txtComposeNeedLeft);
            this._lineComposeNeed = UIFactory.bg(0, 75, 256, 2, this._composeNeedContianer, ImagesConst.SplitLine);
            this._composeContianer = UIFactory.sprite(0, 194);
            this._txtCompose = UIFactory.gTextField(Language.getString(20770), 0, 0, 100, 20, this._composeContianer);
            this._txtCompose.textColor = GlobalStyle.colorChenUint;
            this._txtComposeLeft = new AutoLayoutTextContainer();
            this._txtComposeLeft.x = this._txtCompose.x;
            this._txtComposeLeft.y = this._txtCompose.y + 25;
            this._txtComposeLeft.verticalGap = -7;
            this._composeContianer.addChild(this._txtComposeLeft);
            return;
        }// end function

        private function updateLayout() : void
        {
            this._curY = this._txtBasic.y;
            this._txtBasicLeft.y = this._curY + 25;
            this._curY = this._txtBasicLeft.y + this._txtBasicLeft.height;
            this._lineBasic.y = this._curY;
            this._curY = this._lineBasic.y + this._lineBasic.height;
            if (this._activeSkillContianer.parent)
            {
                this._activeSkillContianer.y = this._curY + 3;
                this._lineAcitveSkill.y = this._txtActiveSkillDesc.y + this._txtActiveSkillDesc.textHeight + 5;
                this._txtActiveSkillDesc.height = this._txtActiveSkillDesc.textHeight + 8;
                this._curY = this._activeSkillContianer.y + this._activeSkillContianer.height;
            }
            if (this._unActiveSKillContianer.parent)
            {
                this._unActiveSKillContianer.y = this._curY + 3;
                this._lineUnactiveSkill.y = this._txtUnActiveSkillDesc.y + this._txtUnActiveSkillDesc.textHeight + 5;
                this._txtUnActiveSkillDesc.height = this._txtUnActiveSkillDesc.textHeight + 8;
                this._curY = this._unActiveSKillContianer.y + this._unActiveSKillContianer.height;
            }
            if (this._composeNeedContianer.parent)
            {
                this._composeNeedContianer.y = this._curY + 3;
                this._lineComposeNeed.y = this._txtComposeNeedLeft.y + this._txtComposeNeedLeft.height;
                this._curY = this._composeNeedContianer.y + this._composeNeedContianer.height + 5;
            }
            if (this._composeContianer.parent)
            {
                this._composeContianer.y = this._curY + 3;
                this._curY = this._composeContianer.y + this._composeContianer.height;
            }
            return;
        }// end function

        private function updateName() : void
        {
            this._txtName.width = _scaleBg.width;
            this._txtName.htmlText = ItemsUtil.getItemWholeName(this._data, true);
            this._txtName.x = -6;
            return;
        }// end function

        public function set equiped(param1:Boolean) : void
        {
            if (param1)
            {
                if (this._bmpEquiped == null)
                {
                    this._bmpEquiped = UIFactory.bitmap(ImagesConst.EquipedLabel, -10, 18);
                }
                contentContainer2D.addChild(this._bmpEquiped);
            }
            else
            {
                DisplayUtil.removeMe(this._bmpEquiped);
            }
            return;
        }// end function

        public function setBuyback(param1:int) : void
        {
            return;
        }// end function

    }
}
